package main

import (
	"github.com/spf13/cobra"
	rcmd "wzgames/cmd"
	"wzgames/internal/app/impl/routower"
	"wzgames/internal/gloader"
)

var (
	nodeId string

	sCmd = &cobra.Command{
		Use:   "routower",
		Short: "WZ Big Roulette Control Service.",
		Long:  "WZ Big Roulette Control Service.",
		PreRun: func(cmd *cobra.Command, args []string) {
			cfgFile, err := rcmd.RootCmd().PersistentFlags().GetString("config")
			if err == nil {
				err = gloader.Res().Start(cfgFile, nodeId)
			}
			if err != nil {
				panic(err)
			}
		},
		Run: func(cmd *cobra.Command, args []string) {
			err := routower.RunServer()
			if err != nil {
				panic(err)
			}
		},
	}
)

func main() {
	sCmd.Flags().StringVar(&nodeId, "node", "", "node id")
	rcmd.RootCmd().AddCommand(sCmd)

	rcmd.Execute()
}
